package com.java.portal.dal.util;

import java.net.URL;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

import com.java.portal.common.util.StreamUtil;
import com.java.portal.dal.exception.PortalDALException;

public class HibernateUtil
{
	public HibernateUtil()
	{

	}

	private static final SessionFactory	sessionFactory;
	private static final SessionFactory	statisticsSessionFactory;

	static
	{
		try
		{
			URL confURL = StreamUtil.getResource("hibernate.cfg.xml");
			sessionFactory = new AnnotationConfiguration().configure(confURL).buildSessionFactory();

			confURL = StreamUtil.getResource("hibernate.statistics.cfg.xml");
			statisticsSessionFactory = new AnnotationConfiguration().configure(confURL).buildSessionFactory();
		} catch (Throwable e)
		{
			throw new PortalDALException(e);
		}
	}

	public static SessionFactory getSessionFactory()
	{
		return sessionFactory;
	}

	public static SessionFactory getStatisticsSessionfactory()
	{
		return statisticsSessionFactory;
	}
}
